package com.big.spike.service.impl;

import com.big.common.exception.BigException;
import com.big.common.result.ResultCodeEnum;
import com.big.common.utils.RedisScript;
import com.big.spike.service.StockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.*;


@Service
@Slf4j
public class StockServiceImpl implements StockService {


    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    RedisScript redisScript= RedisScript.getInstance();


    @Override
    public boolean changeStock(String Key) {
        List<String>keys=Arrays.asList(Key);
        Long execute = (Long) redisTemplate.execute(redisScript.decrStockScript, keys);
         log.info("值：{}",execute);
        return execute>=1L ? true : false;
    }

    @Override
    public Long showStock(String Key) {
        List<String>keys=Arrays.asList(Key);
        Long execute = (Long) redisTemplate.execute(redisScript.showStock, keys);
        log.info("值：{}",execute);
        return execute;
    }


}
